package com.smmisia.shop.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.smmisia.shop.constant.ProductEvent;
import com.smmisia.shop.constant.ProductStateEnum;
import lombok.Data;

/**
 * 
 * @TableName product_stream
 */
@TableName(value ="product_stream")
@Data
public class ProductStream implements Serializable {
    /**
     * 主键ID（自增主键）
     */
    @TableId
    private Long id;

    /**
     * 商品id
     */
    private Long productId;

    /**
     * 商品名称
     */
    private String name;

    /**
     * 商品封面
     */
    private String cover;

    /**
     * 商品类目id
     */
    private String classId;

    /**
     * 商品图片
     */
    private String images;

    /**
     * 价格
     */
    private BigDecimal price;

    /**
     * 商品数量
     */
    private Long quantity;

    /**
     * 详情
     */
    private String detail;

    /**
     * 可销售库存
     */
    private Long saleableInventory;

    /**
     * 幂等号
     */
    private String identifier;

    /**
     * 已占用库存
     */
    private Long occupiedInventory;

    /**
     * 状态
     */
    private ProductStateEnum state;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 流水类型
     */
    private ProductEvent streamType;

    /**
     * 发售时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime saleTime;

    /**
     * 逻辑删除，0为未删除，非0为已删除
     */
    private Integer deleted;

    /**
     * 乐观锁版本
     */
    private Integer lockVersion;

    /**
     * 创建者
     */
    private Integer creatorId;

    /**
     * 修改时间
     */
    private LocalDateTime updateTime;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        ProductStream other = (ProductStream) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
            && (this.getProductId() == null ? other.getProductId() == null : this.getProductId().equals(other.getProductId()))
            && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
            && (this.getCover() == null ? other.getCover() == null : this.getCover().equals(other.getCover()))
            && (this.getClassId() == null ? other.getClassId() == null : this.getClassId().equals(other.getClassId()))
            && (this.getImages() == null ? other.getImages() == null : this.getImages().equals(other.getImages()))
            && (this.getPrice() == null ? other.getPrice() == null : this.getPrice().equals(other.getPrice()))
            && (this.getQuantity() == null ? other.getQuantity() == null : this.getQuantity().equals(other.getQuantity()))
            && (this.getDetail() == null ? other.getDetail() == null : this.getDetail().equals(other.getDetail()))
            && (this.getSaleableInventory() == null ? other.getSaleableInventory() == null : this.getSaleableInventory().equals(other.getSaleableInventory()))
            && (this.getIdentifier() == null ? other.getIdentifier() == null : this.getIdentifier().equals(other.getIdentifier()))
            && (this.getOccupiedInventory() == null ? other.getOccupiedInventory() == null : this.getOccupiedInventory().equals(other.getOccupiedInventory()))
            && (this.getState() == null ? other.getState() == null : this.getState().equals(other.getState()))
            && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
            && (this.getStreamType() == null ? other.getStreamType() == null : this.getStreamType().equals(other.getStreamType()))
            && (this.getSaleTime() == null ? other.getSaleTime() == null : this.getSaleTime().equals(other.getSaleTime()))
            && (this.getDeleted() == null ? other.getDeleted() == null : this.getDeleted().equals(other.getDeleted()))
            && (this.getLockVersion() == null ? other.getLockVersion() == null : this.getLockVersion().equals(other.getLockVersion()))
            && (this.getCreatorId() == null ? other.getCreatorId() == null : this.getCreatorId().equals(other.getCreatorId()))
            && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getProductId() == null) ? 0 : getProductId().hashCode());
        result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
        result = prime * result + ((getCover() == null) ? 0 : getCover().hashCode());
        result = prime * result + ((getClassId() == null) ? 0 : getClassId().hashCode());
        result = prime * result + ((getImages() == null) ? 0 : getImages().hashCode());
        result = prime * result + ((getPrice() == null) ? 0 : getPrice().hashCode());
        result = prime * result + ((getQuantity() == null) ? 0 : getQuantity().hashCode());
        result = prime * result + ((getDetail() == null) ? 0 : getDetail().hashCode());
        result = prime * result + ((getSaleableInventory() == null) ? 0 : getSaleableInventory().hashCode());
        result = prime * result + ((getIdentifier() == null) ? 0 : getIdentifier().hashCode());
        result = prime * result + ((getOccupiedInventory() == null) ? 0 : getOccupiedInventory().hashCode());
        result = prime * result + ((getState() == null) ? 0 : getState().hashCode());
        result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
        result = prime * result + ((getStreamType() == null) ? 0 : getStreamType().hashCode());
        result = prime * result + ((getSaleTime() == null) ? 0 : getSaleTime().hashCode());
        result = prime * result + ((getDeleted() == null) ? 0 : getDeleted().hashCode());
        result = prime * result + ((getLockVersion() == null) ? 0 : getLockVersion().hashCode());
        result = prime * result + ((getCreatorId() == null) ? 0 : getCreatorId().hashCode());
        result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", productId=").append(productId);
        sb.append(", name=").append(name);
        sb.append(", cover=").append(cover);
        sb.append(", classId=").append(classId);
        sb.append(", images=").append(images);
        sb.append(", price=").append(price);
        sb.append(", quantity=").append(quantity);
        sb.append(", detail=").append(detail);
        sb.append(", saleableInventory=").append(saleableInventory);
        sb.append(", identifier=").append(identifier);
        sb.append(", occupiedInventory=").append(occupiedInventory);
        sb.append(", state=").append(state);
        sb.append(", createTime=").append(createTime);
        sb.append(", streamType=").append(streamType);
        sb.append(", saleTime=").append(saleTime);
        sb.append(", deleted=").append(deleted);
        sb.append(", lockVersion=").append(lockVersion);
        sb.append(", creatorId=").append(creatorId);
        sb.append(", updateTime=").append(updateTime);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }

    public ProductStream(Product product, String identifier, ProductEvent streamType) {
        this.productId = product.getId();
        this.name = product.getName();
        this.cover = product.getCover();
        this.classId = product.getClassId();
        this.price = product.getPrice();
        this.quantity = product.getQuantity();
        this.detail = product.getDetail();
        this.saleableInventory = product.getSaleableInventory();
        this.occupiedInventory = product.getOccupiedInventory();
        this.state = product.getState();
        this.createTime = product.getCreateTime();
        this.streamType = streamType;
        this.saleTime = product.getSaleTime();
        this.identifier = identifier;
        this.setImages(product.getImages());
        this.setLockVersion(product.getLockVersion());
        this.setDeleted(product.getDeleted());
    }

    public ProductStream(Long id, Long productId, String name, String cover, String classId, String images, BigDecimal price, Long quantity, String detail, Long saleableInventory, String identifier, Long occupiedInventory, ProductStateEnum state, LocalDateTime createTime, ProductEvent streamType, LocalDateTime saleTime, Integer deleted, Integer lockVersion, Integer creatorId, LocalDateTime updateTime) {
        this.id = id;
        this.productId = productId;
        this.name = name;
        this.cover = cover;
        this.classId = classId;
        this.images = images;
        this.price = price;
        this.quantity = quantity;
        this.detail = detail;
        this.saleableInventory = saleableInventory;
        this.identifier = identifier;
        this.occupiedInventory = occupiedInventory;
        this.state = state;
        this.createTime = createTime;
        this.streamType = streamType;
        this.saleTime = saleTime;
        this.deleted = deleted;
        this.lockVersion = lockVersion;
        this.creatorId = creatorId;
        this.updateTime = updateTime;
    }
}